package com.designpatterns.singletonpattern;

/**
 * 懒汉式单例
 */
public class SingletonLazy {
    /**
     * private禁止外界随意访问 static使用类变量缓存实例
     */
    private static SingletonLazy singletonLazy;

    /**
     * 私有化构造方法禁止外界随意创建本类实例
     */
    private SingletonLazy() {
    }

    /**
     * 对外暴露公共方法供外界获取该单例
     */
    public static SingletonLazy getSingletonLazy() {
        if (singletonLazy == null) {
            Thread.yield();
            singletonLazy = new SingletonLazy();
        }
        return singletonLazy;
    }
}
